var express = require('express');
var router = express.Router();
var db = require('../model/index')

/* 查询所有管理员 */
router.get('/getuser', function(req, res, next) {
    // console.log('req.query', req.query);
    let mysql = ''
    if (req.query.type === '学生') {
        mysql = `SELECT student.*,dormlist.type as dormType FROM student 
        JOIN dormlist ON student.stuDormId = dormlist.id
        WHERE stuUserId = ? AND stuPas = ?`
    } else if (req.query.type === '管理员') {
        mysql = `SELECT * FROM user WHERE userId = ? AND password = ?`
    }
    db(mysql, [req.query.username, req.query.password], function(err, data) {
        console.log('err', err);
        if (err) {
            return res.json({
                code: 500,
                msg: '服务器报错，请稍后重试'
            })
        }
        // console.log('data数据', data);
        res.json({
            code: 200,
            msg: '查询管理员成功',
            data: data
        })

    })
});

module.exports = router;